﻿namespace SPWikiProvisioning.Extensions
{
    #region Usings

    using Microsoft.SharePoint;

    #endregion

    internal static class SPWebExtensions
    {
        internal static SPList GetPagesList(this SPWeb web)
        {
            SPList pagesList = web.Lists.EnsureSitePagesLibrary();

            if (pagesList == null)
            {
                throw new SPException(SPResource.GetString("ListGone", new object[0]));
            }

            if (pagesList.BaseTemplate != SPListTemplateType.WebPageLibrary)
            {
                throw new SPException(SPResource.GetString("OnlyInWikiLibraries", new object[0]));
            }

            if (pagesList.ParentWeb != web)
            {
                throw new SPException(SPResource.GetString("WikiNotInWebException", new object[0]));
            }

            return pagesList;
        }
    }
}
